import Vue from 'vue'
import Vuex from 'vuex'
import myRequest from '@/store/request.js'
Vue.use(Vuex)

const store = new Vuex.Store({
	state:{ //全局变量定义处
		hasLogin:false,   //用户是否登录
		token:'',
		userInfo:{},      //用于存放用户账号数据
		cityInfo:{}, //存放定位后获取的城市信息，地名、经纬度
		mapScale:11, //游客首页地图默认缩放级别
		user: {//聊天详情
				home: {
					id: 1,
					name: 'tax',
					img: 'static/images/picture.png'
				},
				customer: {
					id: 2,
					name: 'customer',
					img: 'static/images/gict.png'
				}
			}
	},
	updated:function(){
			console.log('message update:'+ this.scrollTop);
		},
	mutations:{  //全局方法定义处
		login(state,provider){
			state.hasLogin = true;
			state.userInfo = provider;  //将请求中res.data.user对象存入provider
			uni.setStorage({  //把用户信息保存到本地
				key:'token',
				data:provider.token
			})
			uni.setStorage({  //把用户信息保存到本地
				key:'userInfo',
				data:provider.user
			})
		},
		logout(state){
			state.hasLogin = false;
			state.userInfo = {};
			uni.removeStorage({
				key:'userInfo',   //根据键值移除对应位置的缓存数据
			})
		},
		setCity(state,provider){
			uni.setStorage({  //把用户信息保存到本地
				key:'cityInfo',
				data:provider
			})
		},
		setScale(state,provider){
			uni.setStorage({  //把用户信息保存到本地
				key:'mapScale',
				data:provider
			})
		}
	}
})
export default store